package ac.manchester.cs.afzal.term_classifier.term_similarities;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;



public class Lexical_Profile_Impl
{

    public Lexical_Profile_Impl()
    {
    }

    public Set term_grams(String element, int gram)
    {
        Set set1 = new HashSet();
        String setElement;
        int i = 0;
        int j = gram;
        if(element.length() <= gram)
        {
            set1.add(element);
            return set1;
        }
        else
        {
            while(j <= element.length())
            {
                setElement = element.substring(i, j);
                set1.add(setElement);
                i ++;
                j ++;
            }
        }
        Iterator setIterator = set1.iterator();
        while(setIterator.hasNext())
        {
            System.out.println("Value of Set Element is : " + setIterator.next());
        }
        System.out.println("Size of set is : " + set1.size());
        return set1;
    }

    public Vector term_profiles(String[] str)
    {
        Vector set1 = new Vector();
        String setElement;
        int i = 0;
        int j = 2;

        if(str.length == 1)
        {
            set1.add(str[0]);
            return set1;
        }
        else
        {
            try
            {
                while(i < str.length)
                {
                    set1.add(str[i]);
                    i ++;
                }
                i = 0;
                while(j < str.length)
                {
                    while(j > i)
                    {
                        setElement = str[i] + " " + str[i + 1];
                        set1.add(setElement.toString());
                        i ++;
                        setElement = "";
                    }
                    j ++;
                }
            }
            catch (Exception ex)
            {
                System.out.println("Value of Exception in term profiles is : " + ex.getStackTrace());
            }
        }
        return set1;
    }
}
